package com.song.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.song.common.enums.BusinessType;
import com.song.common.result.R;
import com.song.common.util.ExcelUtils;
import io.swagger.annotations.Api;
import com.song.framework.annotation.RateLimiter;
import com.song.module.admin.entity.ApChef;
import com.song.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.song.common.response.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.song.module.admin.service.IApChefService;
import com.song.module.admin.request.ApChefRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 厨师控制层
 *
 * @date 2024-03-06
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "厨师接口管理",tags = "厨师接口管理")
@RequestMapping("/admin/apChef" )
public class ApChefController {

    private final IApChefService iApChefService;

    /**
     * 分页查询厨师列表
     */
    @ApiOperation(value = "分页查询厨师列表")
    @PostMapping("/pageList")
    public R<PageInfo<ApChef>> pageList(@RequestBody ApChefRequest apChefRequest) {
        return R.success(iApChefService.pageList(apChefRequest));
    }

    /**
     * 获取厨师详细信息
     */
    @ApiOperation(value = "获取厨师详细信息")
    @GetMapping(value = "/query/{id}")
    public R<ApChef> detail(@PathVariable("id") Integer id) {
        return R.success(iApChefService.getById(id));
    }

    /**
     * 新增厨师
     */
    @Log(title = "新增厨师", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增厨师")
    @PostMapping("/add")
    public R<Void> add(@RequestBody ApChefRequest apChefRequest) {
        iApChefService.add(apChefRequest);
        return R.success();
    }

    /**
     * 修改厨师
     */
    @Log(title = "修改厨师", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改厨师")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody ApChefRequest apChefRequest) {
        iApChefService.update(apChefRequest);
        return R.success();
    }

    /**
     * 删除厨师
     */
    @Log(title = "删除厨师", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除厨师")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Integer[] ids) {
        iApChefService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出厨师
    *
    * @param response response
    * @throws IOException IOException
    */
    @ApiOperation(value = "导出厨师")
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody ApChefRequest apChefRequest) throws IOException {
        List<ApChef> list = iApChefService.list(apChefRequest);
        ExcelUtils.exportExcel(list, ApChef.class, "厨师信息", response);
    }
}
